package
{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class myButton extends MovieClip
	{
		var numeButon:TextField=new TextField();
		
		var bWidth : int = 80;
		var bHeight : int = 20;
		
		var tWidth : int = 80;
		var tHeight : int = 18;
		
		public function myButton()
		{
			initializare();
			
			this.addEventListener(Event.ADDED_TO_STAGE,addedToStage);
		}
		
		private function addedToStage(e:Event):void
		{
			this.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
			this.addEventListener(MouseEvent.MOUSE_OVER,mouseOver);
		}
		
		private function mouseDown(e:MouseEvent):void
		{
			this.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
			this.addEventListener(MouseEvent.MOUSE_OUT,mouseUp);
			
			deseneazaApasat();
		}
		
		private function mouseUp(e:MouseEvent):void
		{
			this.removeEventListener(MouseEvent.MOUSE_OUT,mouseUp);
			this.removeEventListener(MouseEvent.MOUSE_UP,mouseUp);
			
			deseneaza();
		}
		
		private function mouseOver(e:MouseEvent):void
		{
			this.addEventListener(MouseEvent.MOUSE_OUT,mouseOut);
			
			deseneazaDeasupra();
		}
		
		private function mouseOut(e:MouseEvent):void
		{
			this.removeEventListener(MouseEvent.MOUSE_OUT,mouseOut);
			
			deseneaza();
		}
		
		private function deseneaza():void
		{
			this.graphics.clear();
			
			this.graphics.beginFill(CONST.buton,0.9);
			this.graphics.drawRoundRect(0,0,bWidth,bHeight,5,5);
		}
		
		private function deseneazaApasat():void
		{
			this.graphics.clear();
			this.graphics.beginFill(CONST.butonApasat,0.9);
			this.graphics.drawRoundRect(0,0,bWidth,bHeight,5,5);
		}
		
		private function deseneazaDeasupra():void
		{
			this.graphics.clear();
			
			this.graphics.beginFill(CONST.butonPeste,0.9);
			this.graphics.drawRoundRect(0,0,bWidth,bHeight,5,5);
		}
		
		public function set valid(e:Boolean):void
		{
			if(e == true)
			{
				this.mouseEnabled = true;
			}
			else
			{
				this.mouseEnabled = false;
			}
		}
		
		private function initializare():void
		{	
			deseneaza();
			
			numeButon.x = 1;
			numeButon.y = 1;
			
			numeButon.width = tWidth;
			numeButon.height = tHeight;
			
			numeButon.mouseEnabled = false;
			
			this.addChild(numeButon);
		}
		
		public function set nume(s:String):void
		{
			numeButon.text = s;
		}
		
		public function set culoare(c:uint):void
		{
			numeButon.textColor = c;
		}
	}
}